<h1>anyStrings</h1>

<ul>
<li> <a href="#1">Synopsis</a>
<ul>
<li> <a href="#2">Variables</a>
</ul>
<li> <a href="#3">Example</a>
<li> <a href="#4">Code</a>
<ul>
<li> <a href="#5">Uses</a>
<li> <a href="#6">Main</a>
</ul>
<li> <a href="#7">Author</a>
</ul>
<p>
Selects a string, at random from a set of strings.
</p>
<a name="1"></a><h2>Synopsis</h2>
<pre>
    anyStrings(string  [,skew,repeats,sep])
</pre>
<a name="2"></a><h3>Variables</h3>
<p>
<em>string</em> is a list of paragraphs, with a number on the first
line. These numbers form a probability distribution.  For example:
  
  6  
  "Out of clutter, find simplicity"
  -- Albert Einstein
</p>
<pre>
  3
  "Simplicity is the ultimate sophistication."
  -- Leonardo da Vinci


  1
  "Good design is as little design as possible."
  -- Dieter Rams


  1
  "If it's stupid, and it works, it isn't stupid."
  -- Murphy's laws of combat. 


  1
  "Perfection: when there is nothing left to take away."
  -- Antoine de Saint-Exupery
</pre>
<p>
N strings are returned, biased by the first line numbers. So, in this
example, the first quote appears half the time, the second appears a
quarter of the time and the last appear at much lower frequencies.
</p>
<a name="3"></a><h2>Example</h2>
<p>
(KNIT programmers can run this example using <em>cd quill; make eg10</em>).
</p>
<p>
In the example, the file <tt>etc/tests/anyStrings.in</tt> contains
the string of quotes shown above.
</p>
<p>
Input:
</p>
<pre>
  srand(1); 
  RS=FS="\r\r\r"; 
  getline String &lt;"etc/tests/anyStrings.in"; 
  N=10; 
  while(N--) 
      print "\n" anyStrings(String) 
</pre>
<p>
Output (note that the Einstein quote with the highest probability appears most often):
</p>
<pre>
  "Perfection: when there is nothing left to take away."
  -- Antoine de Saint-Exupery
  
  "Simplicity is the ultimate sophistication."
  -- Leonardo da Vinci
  
  "Out of clutter, find simplicity"
  -- Albert Einstein
  
  "Good design is as little design as possible."
  -- Dieter Rams
  
  "Simplicity is the ultimate sophistication."
  -- Leonardo da Vinci
  
  "Out of clutter, find simplicity"
  -- Albert Einstein
  
  "Good design is as little design as possible."
  -- Dieter Rams
  
  "Out of clutter, find simplicity"
  -- Albert Einstein
  
  "Out of clutter, find simplicity"
  -- Albert Einstein
  
  "Simplicity is the ultimate sophistication."
  -- Leonardo da Vinci
</pre>
<a name="4"></a><h2>Code</h2>

<a name="5"></a><h3>Uses</h3>

<a name="6"></a><h3>Main</h3>
<pre>
 function anyStrings(string,   skew,repeats,sep,             \
                     pmax, paras,para,lines,freq, thing,cdf,memo,out) {
     skew    = default(skew,    1)
     repeats = default(repeats, 1)
     sep     = default(sep,     "\n")
     pmax = split(string,paras,/\n\n/)     
     for(para=1; para&lt;=pmax; para++) {
         lines[0]    = split(paras[para],lines,/\n/)       
         thing       = trim(a2s(lines,"\n",2))
         freq[thing] = lines[1] + 0
     }
     sampleCounts(freq,cdf,memo)
     while(repeats--) 
         push(out,  memo[pick(cdf,skew)])
     return a2s(out,sep)
 }
</pre>
<a name="7"></a><h2>Author</h2>
<p>
Tim Menzies
